package com.hjd.shop.utils;

import org.springframework.context.annotation.Bean;
import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor;
import org.springframework.stereotype.Component;

import java.util.concurrent.ThreadPoolExecutor;

/**
 * @Author: hjd
 * @Date: 2020/11/1 0001 17:54
 * @Des：线程池创建
 */
@Component
public class ThreadPool {
   @Bean
   public ThreadPoolTaskExecutor getThreadPool(){
       ThreadPoolTaskExecutor tp = new ThreadPoolTaskExecutor();
       tp.setCorePoolSize(4);
       tp.setMaxPoolSize(8);
       tp.setQueueCapacity(100);
       tp.setKeepAliveSeconds(60);
       tp.setThreadNamePrefix("Pool-A");
       tp.setRejectedExecutionHandler(new ThreadPoolExecutor.CallerRunsPolicy());
       tp.initialize();
       return tp;
   }
}
